<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>小王的后台</title>
    <style>
      menu {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
        pointer-events: none;
        z-index: 150;
      }

      .menu--visible {
        pointer-events: auto;
      }

      .app-menu {
        background-color: #fff;
        color: #fff;
        position: relative;
        max-width: 400px;
        width: 90%;
        height: 100%;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
        -webkit-transform: translateX(-103%);
        transform: translateX(-103%);
        display: flex;
        flex-direction: column;
        will-change: transform;
        z-index: 160;
        pointer-events: auto;
      }

      .menu--visible .app-menu {
        -webkit-transform: none;
        transform: none;
      }

      .menu--animatable .app-menu {
        transition: all 130ms ease-in;
      }

      .menu--visible.menu--animatable .app-menu {
        transition: all 330ms ease-out;
      }

      .menu:after {
        content: "";
        display: block;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        will-change: opacity;
        pointer-events: none;
        transition: opacity 0.3s cubic-bezier(0, 0, 0.3, 1);
      }

      .menu--visible.menu:after {
        opacity: 1;
        pointer-events: auto;
      }
    </style>
  </head>

  <body>
    <div class="menu">
      <div class="app-menu">ddd</div>
    </div>
    <div class="layout">
      <div class="header">
        <div class="menu-icon">11</div>
      </div>
    </div>
    <script>
      function toggleClassMenu() {
        myMenu.classList.add("menu--animatable");
        if (!myMenu.classList.contains("menu--visible")) {
          myMenu.classList.add("menu--visible");
        } else {
          myMenu.classList.remove("menu--visible");
        }
      }

      function OnTransitionEnd() {
        myMenu.classList.remove("menu--animatable");
      }

      var myMenu = document.querySelector(".menu");
      var oppMenu = document.querySelector(".menu-icon");
      myMenu.addEventListener("transitionend", OnTransitionEnd, false);
      oppMenu.addEventListener("click", toggleClassMenu, false);
      myMenu.addEventListener("click", toggleClassMenu, false);
    </script>
  </body>
</html>
